Fitting PD-NEUT-TOF Si-SEPD¶
This example shows how to refine the crystal structure parameters of Si from neutron diffraction data in a time-of-flight experiment performed on SEPD diffractometer at Argonne.
Import¶
import easydiffraction as ed
Job¶
Create a job — the main object to store all the information
job = ed.Job(type='tof')
Model¶
Create a phase object
phase = ed.Phase(name='si')
Set space group
phase.space_group.name_hm_alt = 'F d -3 m'
Set cell parameters
phase.cell.length_a = 5.43146
Add atoms
phase.atom_sites.append(label='Si',
type_symbol='Si',
fract_x=0,
fract_y=0,
fract_z=0,
occupancy=1,
b_iso_or_equiv=0.529)
Add phase to the job object
job.add_phase(phase=phase)
print(job.phases)
Several values of it_coordinate_system_code have been defined: 2, 1 The default value has been choosen:'2'. Several values of it_coordinate_system_code have been defined: 2, 1 The default value has been choosen:'2'. Collection of 1 phases: ['si']
Show phase info in CIF format
phase = job.phases['si']
print(phase.cif)
data_si _cell_length_a 5.43146 _cell_length_b 5.43146 _cell_length_c 5.43146 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _space_group_name_H-M_ref 'F d -3 m' _space_group_IT_coordinate_system_code 1 loop_ _atom_site_label _atom_site_type_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy _atom_site_adp_type _atom_site_B_iso_or_equiv Si Si 0.00000000 0.00000000 0.00000000 1.00000000 Biso 0.529
Display the crystal structure of a given model
job.show_crystal_structure(id='si')
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
Experiment¶
Load experimentally measured data from a file in XYE format
job.add_experiment_from_file('data/sepd.xye')
Display the experimentally measured data
job.show_experiment_chart()
Define a point background
background_points = [(x, 200) for x in range(0, 35000, 5000)]
print(background_points)
[(0, 200), (5000, 200), (10000, 200), (15000, 200), (20000, 200), (25000, 200), (30000, 200)]
job.set_background(background_points)
Display the experiment chart after setting the background
job.show_experiment_chart()
Analysis¶
Display the analysis chart before setting initial parameter values
job.show_analysis_chart()
Create aliases for the two types of experimental parameters
pattern_params = job.pattern
experiment_params = job.parameters
Change the default value of some instrumental parameters and display the analysis chart again
experiment_params.dtt1 = 7476.91
experiment_params.dtt2 = -1.54
experiment_params.ttheta_bank = 144.845
job.show_analysis_chart()
Change the scale and display the analysis chart again
phase.scale = 10
job.show_analysis_chart()
Change the default values of the peak profile related parameters and display the analysis chart again
experiment_params.alpha0 = 0.024
experiment_params.alpha1 = 0.204
experiment_params.beta0 = 0.038
experiment_params.beta1 = 0.011
experiment_params.sigma0 = 0.0
experiment_params.sigma1 = 0.0
experiment_params.sigma2 = 0.0
job.show_analysis_chart()
Select parameters to be refined in the first round
phase.scale.free = True
pattern_params.zero_shift.free = True
Print parameters to be refined (free parameters) before fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 10.0 | 0.0 |
Start Least-Squares minimization to refine the selected parameters
job.fit()
Fitting successful Duration: 6.56 s Reduced chi: 36.80
Print the refined parameters after fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 12.810954 | 0.112699 | |
| 2 | zero_shift | -4.166396 | 0.052262 | µs |
Display the analysis chart after the first fitting
job.show_analysis_chart()
Allow background parameters to be refined
for background_point in pattern_params.backgrounds[0]:
background_point.y.free = True
Print free parameters before the second fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 12.810954 | 0.112699 | |
| 2 | zero_shift | -4.166396 | 0.052262 | µs |
| 3 | intensity | 200.000000 | 0.000000 | |
| 4 | intensity | 200.000000 | 0.000000 | |
| 5 | intensity | 200.000000 | 0.000000 | |
| 6 | intensity | 200.000000 | 0.000000 | |
| 7 | intensity | 200.000000 | 0.000000 | |
| 8 | intensity | 200.000000 | 0.000000 | |
| 9 | intensity | 200.000000 | 0.000000 |
Start second round of minimization
job.fit()
Fitting successful Duration: 5.04 s Reduced chi: 16.18
Print free parameters after the second fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 13.169738 | 0.075010 | |
| 2 | zero_shift | -4.165397 | 0.033715 | µs |
| 3 | intensity | 269.666225 | 7.992930 | |
| 4 | intensity | 150.600340 | 2.523188 | |
| 5 | intensity | 121.156660 | 1.990883 | |
| 6 | intensity | 136.251201 | 1.988307 | |
| 7 | intensity | 133.911792 | 1.974323 | |
| 8 | intensity | 175.057849 | 2.293309 | |
| 9 | intensity | 183.334800 | 3.224987 |
Display the analysis chart after the second fitting
job.show_analysis_chart()
Select more parameters to be refined in the third round
experiment_params.sigma0.free = True
experiment_params.sigma1.free = True
experiment_params.sigma2.free = True
Disable refinement of background parameters
for background_point in pattern_params.backgrounds[0]:
background_point.y.free = False
Print free parameters before the third fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 13.169738 | 0.075010 | |
| 2 | sigma0 | 0.000000 | 0.000000 | |
| 3 | sigma1 | 0.000000 | 0.000000 | |
| 4 | sigma2 | 0.000000 | 0.000000 | |
| 5 | zero_shift | -4.165397 | 0.033715 | µs |
Start third round of minimization
job.fit()
Fitting successful Duration: 11.88 s Reduced chi: 5.57
Print free parameters after the third fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 14.846289 | 0.046806 | |
| 2 | sigma0 | -4.968327 | 0.923895 | |
| 3 | sigma1 | 66.704832 | 1.503366 | |
| 4 | sigma2 | -10.512966 | 0.172826 | |
| 5 | zero_shift | -3.357013 | 0.034452 | µs |
Display the analysis chart after the third fitting
job.show_analysis_chart()